<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>欢迎页面-X-admin2.2</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="../css/font.css">
        <link rel="stylesheet" href="../css/xadmin.css">

        <link rel="stylesheet" href="../lib/layui/css/layui.css">
        <script src="../lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="../js/xadmin.js"></script>
    </head>
    
    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">演示</a>
                <a>
                    <cite>导航元素</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">

                        </div>

                        <div class="layui-card-body ">
                            <table class="layui-hide" id="test" lay-filter="test"></table>
                        </div>


                        <script type="text/html" id="toolbarDemo">
                            <div class="layui-btn-container">
                                <button class="layui-btn layui-btn-sm" lay-event="deleteCheckData">删除选中行</button>
                                <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
                                <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>

                                <button class="layui-btn" onclick="xadmin.open('添加用户','./product-add.html',800,600)">
                                    <i class="layui-icon"></i>添加</button></div>

                            </div>
                        </script>


                        <script type="text/html" id="linebarDemo">
                            <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
                            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                        </script>

                    </div>
                </div>
            </div>
        </div>
    </body>




    <script>



        layui.use(['laydate', 'form','table'],
        function() {
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#start' //指定元素
            });

            //执行一个laydate实例
            laydate.render({
                elem: '#end' //指定元素
            });

            //表格数据渲染
            var table = layui.table;

            table.render({
                elem: '#test'
                ,url:'/my/log/selectAllLog'
                ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                    layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                    //,curr: 5 //设定初始在第 5 页
                    ,groups: 3 //只显示 1 个连续页码
                    ,first:false //不显示首页
                    ,last: false //不显示尾页

                }
                    ,cols: [[
                    {field: 'id',type:'checkbox'}
                    ,{field:'id', width:80, title: 'ID', sort: true}
                    ,{field:'visitTime', width:80, title: '访问时间'}
                    ,{field:'username', width:80, title: '访问用户'}
                    ,{field:'ip', title: 'IP地址',width:80}
                    ,{field:'url', width:80, title: '访问路径', sort: true}
                    ,{field:'executionTime', width:80, title: '执行时间', sort: true}
                    ,{field:'method', width:80, title: '访问方法', sort: true}
                    ,{toolbar:"#linebarDemo",fixed: 'right', width:270, align:'center',title: "操作"}

                ]]

            });

            //头工具栏事件
            table.on('toolbar(test)', function(obj){
                var checkStatus = table.checkStatus(obj.config.id);

                switch(obj.event){
                    case 'deleteCheckData':
                        var data = checkStatus.data;
                        /*var array = new Array();*/
                        var ids = new Array();
                         for(var i in data){
                             /*array.push(data[i].id);*/
                             ids.push(data[i].id);
                         }

                         //发送ajax请求
                        $.ajax({
                            type:'post',
                            url:'/my/product/deleteProduct',
                            //key=value的形式
                            data: "ids="+ids,

                            success:function(data){
                                // layer.alert(data.msg)
                                layer.msg(data.msg)
                                // window.location.href ="../res?mark=findAll";
                                setTimeout(function () {
                                    window.parent.location.reload();
                                },2000);
                            },
                        });
                        break;


                    //自定义头工具栏右侧图标 - 提示
                    case 'LAYTABLE_TIPS':
                        layer.alert('这是工具栏右侧自定义的一个图标按钮');
                        break;
                };
            });
//行工具栏事件
            //监听工具条
            table.on('tool(test)', function(obj){
                var data = obj.data;
                var id=obj.data.id;
                console.log(data);
                if(obj.event === 'edit'){
                    layer.open({
                        type: 2,
                        content: ['/my/html/product-edit.html','no'], //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                        success: function(layero, index){
                            /*var iframe = window['layui-layer-iframe' + index];
                            // 向子页面的全局函数child传参
                            iframe.child(data); */
                            //获取子窗口
                            var iframeWin = window[layero.find('iframe')[0]["name"]];
                            //调用子窗口函数
                            iframeWin.child(data);
                        },
                        area:['60%','70%']
                    });


                }
                     /*查看*/
                if(obj.event === 'detail'){
                    layer.open({
                        type: 2,
                        content: ['/my/html/product-edit00.html','no'], //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                        success: function(layero, index){
                            /*var iframe = window['layui-layer-iframe' + index];
                            // 向子页面的全局函数child传参
                            iframe.child(data); */
                            //获取子窗口
                            var iframeWin = window[layero.find('iframe')[0]["name"]];
                            //调用子窗口函数
                            iframeWin.child(data);
                        },
                        area:['60%','65%']
                   });
                }
               /*删除*/
                if(obj.event === 'del'){

                    layer.confirm('真的删除行么', function(index){
                        $.ajax({
                            url:"/my/product/deleteById",
                           /* contentType : "application/json;charset=UTF-8",//发送数据的格式*/
                            type:"get",
                            data:"id="+id,
                            success:function (data) {
                                alert(data.msg);
                            }
                        });
                        layer.close(index);
                        location.reload();
                    });
                }
            });
        });









    </script>

</html>
